﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech.Synthesis;
using DevComponents.DotNetBar;
using DTO;
using BUS;

namespace Support_Study_Vocabulary
{
    public partial class frmViewSetting : Office2007Form
    {
        public SpeechSynthesizer _speaker;
        public frmViewSetting()
        {
            InitializeComponent();
        }

        protected List<VOCABULARY> CreateWordsView()
        {
            List<VOCABULARY> lsRes = null;
            if (this.chbViewAll.Checked == true)
            {
                lsRes = VocabularyBUS.getListVocabularies();
            }
            else
            {
                if (this.chbFilter.Checked == true)
                {
                    int idTopic = int.Parse(this.cbTopic.SelectedValue.ToString());
                    if (this.chbNgay.Checked == true)
                    {
                        lsRes = VocabularyBUS.getListVocabulariesbyDateToDate(this.dpkNgayBD.Value, this.dpkNgayKT.Value, idTopic);
                    }
                    else
                    {
                        if (this.chbThang.Checked == true)
                        {
                            lsRes = VocabularyBUS.getListVocabulariesbyMonth(this.dpkThang.Value, idTopic);
                        }                        
                    }
                }
                else
                {
                    if (this.chbNgay.Checked == true)
                    {
                        lsRes = VocabularyBUS.getListVocabulariesbyDateToDate(this.dpkNgayBD.Value, this.dpkNgayKT.Value);
                    }
                    else
                    {
                        if (this.chbThang.Checked == true)
                        {
                            lsRes = VocabularyBUS.getListVocabulariesbyMonth(this.dpkThang.Value);
                        }                        
                    }
                }
            }
            return lsRes;
        }

        private void btnSave_Close_Click(object sender, EventArgs e)
        {
            List<VOCABULARY> lsReview = this.CreateWordsView();
            if (lsReview != null && lsReview.Count > 0)
            {
                frmDanhSachTu frm = new frmDanhSachTu();
                frm.LsSource = lsReview;
                frm._speaker = _speaker;                
                frm.MdiParent = this.MdiParent;
                frm.Show();            
            }
            else
            {
                MessageBox.Show("Không có từ nào.!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }

        private void frmViewSetting_Load(object sender, EventArgs e)
        {            
            List<TOPIC> lsTopic = TopicBUS.getAllTopics();
            this.cbTopic.DisplayMember = "Name";
            this.cbTopic.ValueMember = "idTopic";
            this.cbTopic.DataSource = lsTopic;
        }

        private void chbViewAll_CheckedChanged(object sender, EventArgs e)
        {
            if (this.chbViewAll.Checked == true)
            {
                this.groupBox2.Enabled = false;
                this.chbFilter.Enabled = false;
                this.cbTopic.Enabled = false;
            }
            else
            {
                this.groupBox2.Enabled = true;
                this.chbFilter.Enabled = true;
                this.cbTopic.Enabled = true;
            }
        }
    
        private void chbNgay_CheckedChanged(object sender, EventArgs e)
        {
            if (this.chbNgay.Checked == true)
            {
                this.chbThang.Enabled = false;
                this.dpkThang.Enabled = false;                                
            }
            else
            {
                this.chbThang.Enabled = true;
                this.dpkThang.Enabled = true;                                
            }
        }

        private void chbThang_CheckedChanged(object sender, EventArgs e)
        {
            if (this.chbThang.Checked == true)
            {
                this.chbNgay.Enabled = false;
                this.dpkNgayBD.Enabled = false;
                this.dpkNgayKT.Enabled = false;                                
            }
            else
            {
                this.chbNgay.Enabled = true;
                this.dpkNgayBD.Enabled = true;
                this.dpkNgayKT.Enabled = true;                                
            }
        }

        private void chbFilter_CheckedChanged(object sender, EventArgs e)
        {
            if (chbFilter.Checked == true)
            {
                cbTopic.Visible = true;
            }
            else
            {
                cbTopic.Visible = false;
            }
        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
